package day9;

public
class Demo1 {
    public static synchronized void printA(){
        String name=Thread.currentThread().getName();
        System.out.println(name+"正在执行printA方法");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name+"执行printA方法完毕");
    }
    public static
    void main(String[] args) {
        new Thread(()->{
            // 同步代码块:锁的对象就是参数中的对象
            synchronized (Demo1.class){
                printA();
            }
        },"aaa").start();
        new Thread(()->{
                Demo1.printA();
        },"bbb").start();
    }
}
